package cn.thoughtworks.school.repositories;

import cn.thoughtworks.school.entities.Organization;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface OrganizationRepository extends JpaRepository<Organization, Long> {

  @Query(value = "select o.* from organization o where o.id in (select organizationId " +
    "from userOrganization where userId = :userId)", nativeQuery = true)
  List<Organization> findByUserId(@Param("userId") Long userId);

}
